package com.urms.controller.user;

import com.github.pagehelper.PageInfo;
import com.urms.entity.QueryUserCondition;
import com.urms.entity.User;
import com.urms.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserSerivce userSerivce;

    /**
     * 根据用户id查找用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/getPassword")
    public User getPassword(Integer userId) {
        return  userSerivce.getPassword(userId);
    }


    /**
     * 条件查询
     *
     * @param quc
     * @return
     */
    @GetMapping("/queryUser")
    public PageInfo<User> selectUserByCondition(QueryUserCondition quc) {
        return userSerivce.findUser(quc);
    }

    @PostMapping("/selectByForm")
    public PageInfo<User> select(QueryUserCondition quc){

        return userSerivce.selectUserByQuc(quc);
    }

    /**
     * 添加用户数据
     *
     * @param user
     * @return
     */
    @PostMapping("/insertUser")
    public Integer insertUser(User user) {
        return  userSerivce.insertUser(user);
    }

    /**
     * 根据用户ID删除用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/deleteUserById")
    public Integer deleteUserById(Integer userId) {
        return userSerivce.deleteUserById(userId);
    }

    /**
     * 逻辑删除
     * @param userId
     * @return
     */
    @GetMapping("/updateHidden")
    public  Integer updateHidden(Integer userId){
        return userSerivce.updateHidden(userId);
    }
    @GetMapping("/removeUser")
    public  Integer updateHiddenUsers(Integer[] userIds){
        return userSerivce.removeUserByIds(userIds);
    }
    /**
     * 根据用户ID更新用户信息
     *
     * @param user
     * @return
     */
    @PostMapping("/updateUser")
    public Integer updateUserById(User user) {
        return userSerivce.updateUserById(user);
    }

    /**
     * 根据用户ID更新用户状态
     *
     * @param id
     * @return
     */
    @GetMapping("/updateStatusById")
    public Integer updateUserStatusById(Integer id) {
        return userSerivce.updateUserStatusById(id);
    }

    @PostMapping("/userSelectByCondition")
    public PageInfo<User> userSelectByCondition(QueryUserCondition quc){
        PageInfo<User> pageInfo = userSerivce.userSelectByCondition(quc);
        return pageInfo;
    }

    @GetMapping("/selectByuserName")
    public Integer selectByuserName(String userLoginName){
        return userSerivce.selectByuserName(userLoginName);
    }

    @GetMapping("/selectByPhone")
    public Integer selectByPhone(String userPhone){
        return userSerivce.selectByPhone(userPhone);
    }
}
